Skip to content

fix: RadioGroup should not validate on form reset #8212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2025

Conversation

chirokas
Copy link
Contributor

@chirokas chirokas commented May 9, 2025

Closes #8134

Since the ref is not a stable reference, the previous `onReset` gets unmounted during a React discrete update.

form?.removeEventListener('reset', onReset);
};
}, [ref, onInvalid, onChange, onReset, validationBehavior]);

To solve this, we have to make sure that the `inputRef` is always a stable reference.

I can't clearly explain what happened, but here's a similar case.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! Doesn't look like we can test in jsdom, I tried it in 26.1.0 to see if the reset behaviour changed, but no luck. Probably have to file a bug against them at some point.

@@ -186,7 +186,7 @@ export const Radio = /*#__PURE__*/ (forwardRef as forwardRefType)(function Radio
} = props;
[props, ref] = useContextProps(otherProps, ref, RadioContext);
let state = React.useContext(RadioGroupStateContext)!;
let inputRef = useObjectRef(mergeRefs(userProvidedInputRef, props.inputRef !== undefined ? props.inputRef : null));
let inputRef = useObjectRef(useMemo(() => mergeRefs(userProvidedInputRef, props.inputRef !== undefined ? props.inputRef : null), [userProvidedInputRef, props.inputRef]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct, we usually useMemo with mergeRefs and useObjectRef, it looks like this one was missed

@yihuiliao yihuiliao added this pull request to the merge queue May 19, 2025
github-merge-queue bot pushed a commit that referenced this pull request May 19, 2025
Merged via the queue into adobe:main with commit 6f8ba67 May 19, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RadioGroup validates when reseting Form
3 participants